<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			#a{
				text-align: center;
				position: relative;
				top: 60px;
			}
			.b{
				margin-top: 30px;
				
			}
		</style>
	</head>
	<body>
		<div id="a">
			<div class="b">
				<label>原密码:</label>
				<input type="password" name="pas" />
			</div>
			<div class="b">
				<label>现密码:</label>
				<input type="password" name="pa1" />
			</div>
			<div class="b">
				<label>重输密码:</label>
				<input type="password" name="pa2" />
			</div>
			<div class="b">
				<button type="button" onclick="save()">保存</button>
			</div>
		</div>
		
		<script src="../js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var xuesheng = JSON.parse(sessionStorage.getItem("xuesheng"));
			var username = JSON.parse(sessionStorage.getItem("username"));
			function save(){
				var password = $("input[name='pas']").val();
				var password1 = $("input[name='pa1']").val();
				var password2 = $("input[name='pa2']").val();
				var data = {user:username,id:id,account:ac,password:password1};
				//console.log(password,password1,password2);
				$.each(xuesheng,function(index,item){
					if (password && password1.trim().length>=3 && password1.trim().length>=3){
						if (password === item.password && username === item.user){
							var ac = item.account;
							var id = item.id;
							if (password1 === password2){
								xuesheng.splice(index,1,data);
								alert("修改成功");
								sessionStorage.setItem("xuesheng",JSON.stringify(xuesheng));
							}else{
								alert("两次输入的密码不一致");
							}
						}else{
							alert("输入的密码与原密码不匹配");
						}
					}else{
						alert("需要修改的信息不完善");
					}
				})
			}
		</script>
	</body>
</html>
